package homework4.Intercept;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import java.util.Map;

/**
 * @author CoderXshuai
 */
public class LoginInterceptor extends AbstractInterceptor {
    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        ActionContext context = actionInvocation.getInvocationContext();
        Map request = (Map) context.get("request");
        Object name = request.get("username");
        Map session = context.getSession();
        Object username = session.get("u");
        if (username != null || name != null) {
            return actionInvocation.invoke();
        } else {
            return Action.LOGIN;
        }
    }
}
